<template>
	<scroll-view :scroll-y="true" style="height: 100%;">
		<template v-if="!loading">
			<u-swiper radius='0' height='400rpx' :list="banner" keyName="thumb" @click='clickSwiper'></u-swiper>
			<view class="contentBox">
				<view class="left">
					<view class="contentItem " v-for="(item,index) in finishedCustomers" :key="index"
						@click="jumpDetail(item.id)">
						<image :src="item.thumb_small" mode="aspectFill"></image>
						<view class="styleBox">{{item.style.title}}</view>
						<view class="itemInfo">
							<view class="remark_nameBox">
								<u--text :text='item.remark_name' lines='1' size='26rpx' />
								<u-icon name="heart" color='#999' labelColor='#999' size="28rpx" labelsize='24rpx'
									:label='item.favorite_count'></u-icon>
							</view>
							<view class="map">
								<u--text :iconStyle='{color:"#fff"}' prefixIcon='map' lines='1' color='#fff'
									:text='item.district' size='24rpx' />
							</view>


						</view>
					</view>
				</view>
				<view class="right">
					<view class="contentItem" v-for="(item,index) in unfinishedCustomers" :key="index"
						@click="jumpDetail(item.id)">
						<image :src="item.thumb_small" mode="aspectFill"></image>
						<view class="styleBox">{{item.style.title}}</view>
						<view class="itemInfo">
							<view class="remark_nameBox">
								<u--text :text='item.remark_name' lines='1' size='26rpx' />
								<u-icon name="heart" color='#999' labelColor='#999' size="28rpx" labelsize='24rpx'
									:label='item.favorite_count'></u-icon>
							</view>
							<view class="map">
								<u--text :iconStyle='{color:"#fff"}' lines='1' prefixIcon='map' color='#fff'
									:text='item.district' size='24rpx' />
							</view>


						</view>
					</view>
				</view>
			</view>
		</template>
		<template v-else>
			<view style="height: 400rpx;" class="Skeleton" />
			<view class="contentBox">
				<view class="left">
					<view class="contentItem " v-for="(item,index) in 8" :key="index">
						<view class="Skeleton" style="height: 300rpx;" />
						<view class="itemInfo">
							<view v-for="item in 1" :key="item" style="height: 30rpx;" class="Skeleton" />
						</view>
					</view>
				</view>
				<view class="right">
					<view class="contentItem " v-for="(item,index) in 8" :key="index">
						<view class="Skeleton" style="height: 300rpx;" />
						<view class="itemInfo">
							<view v-for="item in 1" :key="item" style="height: 30rpx;" class="Skeleton" />
						</view>
					</view>
				</view>
			</view>

		</template>
		<template v-if="!loading">
			<template >
				<view class="add" v-if='userInfo.is_company_administrator&&token' @click="jumpShop">
					<u-icon color='#fff' name='home' size='50rpx' />
				</view>
			</template>
		</template>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				isAdministrator: false,
				userInfo: uni.getStorageSync('user'),
				token: uni.getStorageSync('token'),
				banner: [],
				loading: true,
				finishedCustomers: [],
				unfinishedCustomers: []
			}
		},
		mounted() {
			uni.showLoading({
				title: '加载中...'
			})
			this.$api.Home.List().then(res => {
				this.banner = res.data.gSliderBanners
				this.isAdministrator = res.data.isAdministrator
				uni.setStorageSync('unAuthorizedCount', res.data.unAuthorizedCount);
				const arr = [...res.data.customers.decorates]
				this.finishedCustomers = arr.filter((item, index) => {
					if (arr.length % 2 != 0) {
						if (index == 0) return true
					}
					if (index % 2 != 0) {
						return true
					}
				})
				this.unfinishedCustomers = arr.filter((item, index) => {

					if (arr.length % 2 == 0) {
						if (index == 0) return true
					} else {
						if (index == 0) return false
					}
					if (index % 2 == 0) {
						return true
					}
				})
				uni.hideLoading()
				this.loading = false
			}).catch(err => {
				uni.hideLoading()
				uni.$u.toast(err.message)
			})
		},
		methods: {
			jumpShop() {
				this.$utils.navigateTo({
					url: '/customer_company/index'
				})
			},
			jumpDetail(id) {
				if(this.userInfo?.is_company_administrator){
					this.$utils.navigateTo({
						url: '/customer_company/detail?id=' + id
					})
				}else{
					this.$utils.navigateTo({
						url: '/customer/detail_c?id=' + id
					})
				}
				
			},
			clickSwiper(e) {
				let url = this.banner[e].url
				this.$utils.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.remark_nameBox {
		display: flex;
		align-items: center;
	}

	.left {
		width: 49%;
		float: left;
	}

	.right {
		width: 49%;
		float: right;
	}

	.typeTitle {
		font-size: 30rpx;
		display: flex;
		align-items: center;
		margin: 20rpx auto;
		width: 94vw;
		justify-content: space-between;

		&:before {
			content: '';
			background-color: #bfbfbf;
			flex: 1;
			height: 2rpx;
			display: inline-block;
			margin-right: 40rpx;
		}

		&:after {
			content: '';
			background-color: #bfbfbf;
			flex: 1;
			height: 2rpx;
			display: inline-block;
			margin-left: 40rpx;
		}
	}



	.contentBox {
		margin: 20rpx auto;
		width: 94vw;

		image {
			width: 100%;
			background-color: #000;
			height: 300rpx;
			border-radius: 8rpx 8rpx 0 0;
			;
			box-shadow: 0 0 20rpx #aaa;
		}

		.contentItem {
			background-color: #fff;
			border-radius: 8rpx;
			overflow: hidden;
			margin-bottom: 20rpx;
			position: relative;
			box-shadow: 0 0 10rpx #ddd;

			.map {
				position: absolute;
				top: 260rpx;
				left: 20rpx;
				width: 300rpx;
			}
		}



		.styleBox {
			top: 10rpx;
			right: 10rpx;
			border-radius: 8rpx;
			padding: 10rpx 20rpx;
			background-color: rgba(255, 255, 255, 0.5);
			position: absolute;
		}
	}

	.itemInfo {
		padding: 10rpx 20rpx 0;

		>view {
			margin-bottom: 20rpx;
		}
	}

	.activeIcon {
		background-color: rgba(57, 117, 198, 0.2);
		height: 180rpx;
		display: flex;
		margin-bottom: 20rpx;
		align-items: center;
		justify-content: center;

		>view {
			font-size: 35rpx;
			background: linear-gradient(to right bottom, #357ABE, #48B0FF, #356CBE);
			color: transparent;
			font-weight: 600;
			/*文字颜色为透明*/
			background-clip: text;
			/*以文字截切背景*/
		}
	}

	.add {
		position: fixed;
		right: 5vw;
		bottom: 20vh;
		border-radius: 100%;
		box-shadow: 0 0 10rpx #ddd;
		background: rgba(0, 0, 0, 0.7);
		padding: 20rpx;

	}
</style>